<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<html>
<head>
    <title>数据选择</title>
    <jsp:include page="../body/jtree.jsp" flush="true"/>


    <SCRIPT type="text/javascript">
        <!--
        var setting = {
            view: {
                addHoverDom: addHoverDom,
                removeHoverDom: removeHoverDom,
                selectedMulti: false
            },
            check: {enable: true,chkStyle: "radio",radioType: "level"},
            data: {
                simpleData: {
                    enable: true
                }
            },
            edit: {
                enable: false
            },
            callback: {onCheck: zTreeOnCheck}
        };
        function zTreeOnCheck(event, treeId, treeNode) {
            $("#ztreeid").val(treeNode.id);
            $("#ztreesname").val(treeNode.name);
        };

        var callbackdata = function () {
            var data = {
                id: $("#ztreeid").val(),
                menuName:$("#ztreesname").val(),
            };
            return data;
        }
        var zNodes;
        function  zNodes1 () {
            $.ajax({
                type:'get',
                dataType:'json',
                url:'/menu/treeData',
                async:false,
                success:function (data) {
                    zNodes= data;
                },
                error : function () {
                    alert("获取失败")
                }
            })
        };

        $(document).ready(function(){
            zNodes1();
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        });

        var newCount = 1;
        function addHoverDom(treeId, treeNode) {
            var sObj = $("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
            var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                + "' title='add node' onfocus='this.blur();'></span>";
            sObj.after(addStr);
            var btn = $("#addBtn_"+treeNode.tId);
            if (btn) btn.bind("click", function(){
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
                return false;
            });
        };
        function removeHoverDom(treeId, treeNode) {
            $("#addBtn_"+treeNode.tId).unbind().remove();
        };
        //-->
    </SCRIPT>
</head>
<body>
<input type="hidden" id="ztreeid"/>
<input type="hidden" id="ztreesname"/>
<ul id="treeDemo" class="ztree"></ul>
</body>

</html>